package org.teremail.server;

import org.teremail.client.MailServiceAsync;
import org.teremail.client.MessageSummary;
import org.teremail.client.SummaryController;

import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;

public class GwtTestSummaryController extends GWTTestCase {

    public String getModuleName() {
        return "org.teremail.TestTereMailClient";
    }
    
    public void testStuff() {
        FlexTable ft = new FlexTable();
        
        final String mailboxName = "homer";
        final String folderName = "INBOX";
        final MessageSummary[] summaries = new MessageSummary[3];
        summaries[0] = new MessageSummary(1, "bart@example.com", "Test 1", "2008-01-01");
        summaries[1] = new MessageSummary(2, "lisa@example.com", "Test 2", "2008-02-02");
        summaries[2] = new MessageSummary(3, "marge@example.com", "Test 3", "2008-03-03");
        
        SummaryController sc = new SummaryController(ft, VerificationHelper.mockErrorHandler, 
                new MailServiceAsync() {
                    public void getFolders(String mailbox, AsyncCallback<String[]> callback) {
                    }
    
                    public void getMessage(String mailbox, String folder, int uid, 
                                           AsyncCallback<String> asyncCallback) {
                    }
    
                    public void getMessageSummaries(String mailbox, String folder,
                                                    AsyncCallback<MessageSummary[]> asyncCallback) {
                        assertEquals(mailboxName, mailbox);
                        assertEquals(folderName, folder);
                        asyncCallback.onSuccess(summaries);
                    }
                });
        
        sc.fetchMessages(mailboxName, folderName);
        assertNotNull(sc.getFolder());
        assertEquals(summaries.length + 1, ft.getRowCount());
    }
    
}
